<?php
/**
 * MNews 
 * - Define class spCategory
 * @author ANHTAM
 * @since 1.1 - Sep 27, 2011
 * $Id: $
 */
include_once(DOCUMENT_ROOT . "/lib/core/BaseProcess.class.php");
class MNews extends BaseProcess {
	public function __construct() {
		parent::__construct("m_news");
		$this->primaryKeyName = "id";
	}
	
	public function updateLuotXem($id) {
		if (is_numeric($id)) {
			$attr = array('id' => $id);
			$field = array('luotxem');
			$data = $this->getOneByAttr($attr, $field);
			if (is_array($data) && !empty($data)) {
				$this->setAttribute('luotxem', $data['luotxem'] + 1);
				parent::update(array('id' => $data['id']));
			}
		}
	}
	
	public function getListFromNews($idc, $fla = false, $limit=array()) {
		if ($fla) {
			$sql = "SELECT *";
		} else {
			$sql = "SELECT id, idc, tieude, tomtat";
		}
		$sql .= " FROM " . $this->tableName . " WHERE idc='" . $idc . "'";
		$sql .= " ORDER BY update_at DESC";
		if (is_array($limit) && !empty($limit)) {
			$sql .= " LIMIT ".$limit[0].",".$limit[1];
		}
		$rs = $this->execute($sql, ADODB_FETCH_ASSOC);
        $data = array();
        if ($rs) {
            while (! $rs->EOF && $item = $rs->FetchRow()) {
                $data[] = $item;
            }
        }
        return $data;
	}
}
?>